package com.ruoyi.web.controller.tongban;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.tongban.domain.TInstitution;
import com.ruoyi.tongban.service.ITInstitutionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 机构Controller
 * 
 * @author caiyanshan
 * @date 2021-03-09
 */
@RestController
@RequestMapping("/tongban/institution")
public class TInstitutionController extends BaseController
{
    @Autowired
    private ITInstitutionService tInstitutionService;

    /**
     * 查询机构列表
     */
    @PreAuthorize("@ss.hasPermi('tongban:institution:list')")
    @GetMapping("/list")
    public TableDataInfo list(TInstitution tInstitution)
    {
        startPage();
        List<TInstitution> list = tInstitutionService.selectTInstitutionList(tInstitution);
        return getDataTable(list);
    }
    
    /**
     * 查询机构列表
     */
    @GetMapping("/listData")
    public AjaxResult listData()
    {
        TInstitution tInstitution = new TInstitution();
        List<TInstitution> list = tInstitutionService.selectTInstitutionList(tInstitution);
        return AjaxResult.success(list);
    }

    /**
     * 导出机构列表
     */
    @PreAuthorize("@ss.hasPermi('tongban:institution:export')")
    @Log(title = "机构", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TInstitution tInstitution)
    {
        List<TInstitution> list = tInstitutionService.selectTInstitutionList(tInstitution);
        ExcelUtil<TInstitution> util = new ExcelUtil<TInstitution>(TInstitution.class);
        return util.exportExcel(list, "institution");
    }

    /**
     * 获取机构详细信息
     */
    @PreAuthorize("@ss.hasPermi('tongban:institution:query')")
    @GetMapping(value = "/{institutionId}")
    public AjaxResult getInfo(@PathVariable("institutionId") Long institutionId)
    {
        return AjaxResult.success(tInstitutionService.selectTInstitutionById(institutionId));
    }

    /**
     * 新增机构
     */
    @PreAuthorize("@ss.hasPermi('tongban:institution:add')")
    @Log(title = "机构", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TInstitution tInstitution)
    {
        return toAjax(tInstitutionService.insertTInstitution(tInstitution));
    }

    /**
     * 修改机构
     */
    @PreAuthorize("@ss.hasPermi('tongban:institution:edit')")
    @Log(title = "机构", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TInstitution tInstitution)
    {
        return toAjax(tInstitutionService.updateTInstitution(tInstitution));
    }

    /**
     * 删除机构
     */
    @PreAuthorize("@ss.hasPermi('tongban:institution:remove')")
    @Log(title = "机构", businessType = BusinessType.DELETE)
	  @DeleteMapping("/{institutionIds}")
    public AjaxResult remove(@PathVariable Long[] institutionIds)
    {
        return toAjax(tInstitutionService.deleteTInstitutionByIds(institutionIds));
    }
}
